package edu.sctu.practice.class02.hujie.online_classes_practice.imooc.Java_IO.class5to1;

import java.io.*;

/**
 * Created by hp on 2015/12/22.
 */
public class IsrAndOswDemo {
    public static void main(String[] args) throws IOException {
        FileInputStream in = new FileInputStream("F:\\桌面文件\\慕课网笔记\\文件传输基础IO流\\1.txt");
        InputStreamReader isr = new InputStreamReader(in, "utf-8");//第二个是默认的项目编码,操作的时候，要写文件本身的编码格式
        FileOutputStream out = new FileOutputStream("F:\\桌面文件\\慕课网笔记\\文件传输基础IO流\\copy1.txt");
        OutputStreamWriter osw = new OutputStreamWriter(out, "utf-8");
//        int c;
//        while ((c=in.read())!=-1){
//            System.out.println((char)c);
//        }
        char[] buffer = new char[8 * 1024];
        int c;
        //批量读取，放入buffer这个字符数组，从第0个位置开始防止，最多放buffer.length
        while ((c = isr.read(buffer, 0, buffer.length)) != -1) {
            String s = new String(buffer, 0, c);
            System.out.println(s);
            osw.write(buffer, 0, c);
            osw.flush();
        }
        osw.close();
        isr.close();
    }
}
